package com.example.service.controller;


import com.example.common.constent.JWTConstent;
import com.example.common.dto.LoginDto;
import com.example.common.vo.Result;
import com.example.service.pojo.Teacher;
import com.example.service.service.TeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("teacher")
@Tag(name = "教师登录")
@RequiredArgsConstructor
public class LoginController {

    private final TeacherService teacherService;

    @PostMapping("login")
    @Operation(summary = "登录接口")
    public Result<Integer> login(LoginDto loginDto){
        Teacher teacher = teacherService.lambdaQuery()
                .select(Teacher::getId)
                .eq(Teacher::getNo, loginDto.getNo())
                .eq(Teacher::getPassword, loginDto.getPassword())
                .one();
        if(teacher==null){
            return Result.fail(JWTConstent.PASSWORD_ERROR_CODE, "账号或密码错误",null);
        }
        return Result.success(teacher.getId());
    }

}
